// 实例
function moveon() {
    var answer = confirm('准备好了吗？');
    if (answer) {
        window.location.href = 'http://www.baidu.com';
    }
}
// setTimeout(moveon, 2000);

// 在文档指定区域显示调试信息
function debug(msg) {
    var log = document.getElementById('debuglog');
    if (!log) {
        log = document.createElement('div');
        log.id = 'debuglog';
        log.innerHTML = '<h1>Debug Log</h1>';
        document.body.appendChild(log);
    }
    var pre = document.createElement('pre');
    var text = document.createTextNode(msg);
    pre.appendChild(text);
    log.appendChild(pre);
}
// debug('log');

// 通过js操作样式控制元素隐藏
function hide(e, reflow) {
    if (reflow) {
        e.style.display = 'none';
    } else {
        e.style.visibility = 'hidden';
    }
}
// 控制文字高亮
function highlight(e) {
    if (!e.className) {
        e.className = 'hilite';
    } else {
        e.className += 'hilite';
    }
}

// load 事件
window.onload = function () {
    var images = document.getElementsByTagName('img');
    // 遍历img标签 添加事件
    for (var i = 0; i < images.length; i++) {
        var image = images[i];
        if (image.addEventListener) {
            image.addEventListener('click', hide, false);
        } else {
            image.attachEvent('onclick', hide);
        }
    }
    function hide(event) {
        event.target.style.visibility = 'hidden';
    }
}
